require("View")

PlayerView = class("PlayerView", View)

---

function PlayerView:initialize()
	
	View.initialize(self)
	
	self.staticMoveBox = false
	self.staticPickupBox = false
	self.staticUnlockBox = false
	
	self.widgets = {}
end

---

function PlayerView:update()
  	
  	self.staticBoxes = {}
  	self.staticBoxSizers = {}
  	 	
	self.rootWindow = wx.wxPanel(gView.frame, wx.wxID_ANY)    
	self.mainSizer = wx.wxBoxSizer(wx.wxVERTICAL)
	self.rootWindow:SetSizer( self.mainSizer )	
	
	gPlayer:sensePossibleActions()
	
	for verb, sentences in pairs(gPlayer.possibleActionDirectory)
	do
		self:addAction(sentences)
	end
	
	for verb, sentences in pairs(gPlayer.lockedActionDirectory)
	do
		self:addAction(sentences, true)
	end
end

---

function PlayerView:addAction(sentences, locked)

	local verb = sentences[1]:getVerb()
	
	if not self.staticBoxes[verb] 
	then
		self.staticBoxes[verb] = wx.wxStaticBox(self.rootWindow, wx.wxID_ANY, verb)
		self.staticBoxSizers[verb] = wx.wxStaticBoxSizer(self.staticBoxes[verb], wx.wxVERTICAL)
		self.mainSizer:Add(self.staticBoxSizers[verb], 0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 5 )
	end
	
	for i, sentence in ipairs(sentences) 
	do 
		local buttonID = self:registerButton(sentence)
		
		local widget = wx.wxButton( self.rootWindow, buttonID, sentence:getDirectObjectName())
		self.staticBoxSizers[verb]:Add( widget,  0, wx.wxGROW+wx.wxALIGN_CENTER+wx.wxALL, 5 )
		
		if locked 
		then
			widget:Disable()
		end			
	end
end

---

function PlayerView:onButtonClick(buttonDescriptor)

	gPlayer.body:execute(buttonDescriptor)
end